package com.link2room.blaster.controller.manager;

import com.link2room.blaster.dto.innerUse.InmailBaseDto;
import com.link2room.blaster.dto.param.base.BlasterBaseParamDto;
import com.link2room.blaster.dto.result.SMSAuthCodeResDto;
import com.link2room.blaster.facade.InMailFacadeService;
import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.blaster.dto.param.inMail.InmailBaseParamDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by LN on 2017/6/30.14:42
 */
@Api(tags = "站内信")
@RestController
@RequestMapping("/manager/mails")
public class InmailController {
    @Resource
    private InMailFacadeService inMailFacadeService;

    @ApiOperation(value = "站内消息列表", response = InmailBaseDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "hasRead", value = "是否已读", paramType = "query", required = false),
            @ApiImplicitParam(name = "hasDone", value = "是否完成", paramType = "query", required = false),
    })
    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto getList(
            @RequestParam(name = "hasRead", required = false) String hasRead,
            @RequestParam(name = "hasDone", required = false) String hasDone
    ) throws Exception {
        InmailBaseParamDto paramDto = new InmailBaseParamDto();
        paramDto.setHasDone(hasDone);
        paramDto.setHasRead(hasRead);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setQueryResult(inMailFacadeService.inmailList(paramDto));
        l2rRs.setResultCode(0);
        return l2rRs;
    }

    @ApiOperation(value = "站内消息详情", response = InmailBaseDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "inmailId", value = "是否已读", paramType = "path", required = false),
    })
    @RequestMapping(value = "/{inmailId}", method = RequestMethod.GET)
    public BaseResultDto getDetail(@PathVariable("inmailId") String inmailId) throws Exception {
        InmailBaseParamDto paramDto = new InmailBaseParamDto();
        paramDto.setInmailId(inmailId);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultInfo(inMailFacadeService.inmailDetail(paramDto));
        l2rRs.setResultCode(0);
        return l2rRs;
    }

    @ApiOperation(value = "站内消息数量统计", response = InmailBaseDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "hasRead", value = "是否已读", paramType = "query", required = false),
            @ApiImplicitParam(name = "hasDone", value = "是否完成", paramType = "query", required = false),
    })
    @RequestMapping(value = "/count", method = RequestMethod.GET)
    public BaseResultDto count(
            @RequestParam(name = "hasRead", required = false) String hasRead,
            @RequestParam(name = "hasDone", required = false) String hasDone
    ) throws Exception {
        InmailBaseParamDto paramDto = new InmailBaseParamDto();
        paramDto.setHasDone(hasDone);
        paramDto.setHasRead(hasRead);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultInfo(inMailFacadeService.countInmail(paramDto));
        l2rRs.setResultCode(0);
        return l2rRs;
    }

    @ApiOperation(value = "读取站内信", response = InmailBaseDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "inmailId", value = "是否已读", paramType = "path", required = false),
    })
    @RequestMapping(value = "/{inmailId}/hasRead", method = RequestMethod.POST)
    public BaseResultDto inmailRead(@PathVariable("inmailId") String inmailId) throws Exception {
        InmailBaseParamDto inmailBaseParamDto = new InmailBaseParamDto();
        inmailBaseParamDto.setInmailId(inmailId);
        inMailFacadeService.inmailRead(inmailBaseParamDto);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }

    @ApiOperation(value = "完成站内信", response = InmailBaseDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "inmailId", value = "是否已读", paramType = "path", required = false),
    })
    @RequestMapping(value = "/{inmailId}/hasDone", method = RequestMethod.POST)
    public BaseResultDto inmailDo(@PathVariable("inmailId") String inmailId) throws Exception {
        InmailBaseParamDto inmailBaseParamDto = new InmailBaseParamDto();
        inmailBaseParamDto.setInmailId(inmailId);
        inMailFacadeService.inmailDone(inmailBaseParamDto);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }
}
